<template>
  <div class="permissions_dialog">
    <el-dialog
      title="价格详情"
      center
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div class="add-table" v-for="(item, index) in tableData" :key="index">
        {{ item.name }}:{{ item.value }}
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">返回</el-button>
        <el-button
          :loading="btnLoading"
          type="primary"
          @click="submitForm('ruleForm')"
          v-no-more-click:3000
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { debounce } from "@u";
import { ApimenuAdd, ApimenuEdit, Apipermission, ApiItemEditprice } from "@a";
export default {
  data() {
    return {
      tableData: [],
      sku_name: "",
      dataList: [
        { code: "sku_name", name: "耗材名称" },
        { code: "price1", name: "价格" } /*
        { code: "price2", name: "交通费" },
        { code: "price3", name: "治疗费" }, */,
      ], // 表格数据
      options: [],
      permissions_loading: false,
      isEDit: false,
      id: "",
      btnLoading: false,
      dialogFormVisible: false,
      form: {
        title: "",
        parent_id: "",
        route: "",
        permissions_id: "",
        navigation: 1,
      },

      rules: {
        title: [
          {
            required: true,
            message: "请输入",
            trigger: ["blur", "change"],
          },
        ],
        route: [
          {
            required: true,
            message: "请输入",
            trigger: ["blur", "change"],
          },
        ],
        permissions_id: [
          {
            required: true,
            message: "请输入",
            trigger: "blur",
          },
        ],
      },
    };
  },

  methods: {
    showDialog(data) {
      console.log(data);
      if (data) {
        let val = JSON.parse(data.price_detail);
        this.tableData = [];
        for (const key in val) {
          this.tableData.push({ name: key, value: val[key] });
        }
        console.log(this.tableData);
      }
      this.dialogFormVisible = true;
    },

    // 提交数据
    submitForm: debounce(function () {
      console.log(this.id);
      ApiItemEditprice(this.tableData, this.id).then((res) => {
        this.$message.success("操作成功！");
        this.$emit("changeList");
        this.handleClose();
      });
    }),

    addData(parmas) {
      ApimenuAdd(parmas)
        .then((res) => {
          this.changeData();
        })
        .finally((_) => {
          this.btnLoading = false;
        });
    },
    editData(parmas) {
      ApimenuEdit(parmas, this.id)
        .then((res) => {
          this.changeData();
        })
        .finally((_) => {
          this.btnLoading = false;
        });
    },
    changeData() {
      this.$message.success("操作成功！");
      this.$emit("changeList");
      this.handleClose();
    },
    handleClose() {
      this.resetForm("ruleForm");
    },
    resetForm(formName) {
      this.dialogFormVisible = false;
      this.$refs.formName.resetFields();
    },
  },

  /*  watch: {
    rowTitle: {
      handler: function (newValue) {
        this.dataList = [];
      },
      immediate: true,
    },
  } */
};
</script>
<style lang="less" scoped></style>
